package dcx.map.editor
{
	import dcx.map.IMapData;
	import dcx.map.MapStaticData;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	
	public class InfoUIManager
	{
		public function InfoUIManager(infoUI:Sprite, staticData:IMapData)
		{
			this.infoUI = infoUI;
			this.staticData = staticData;
			infoUI.visible = false;
			
			for (var i:int = 0; i < infoUI.numChildren; i++) 
			{
				var textField:TextField = infoUI.getChildAt(i) as TextField;
				if (!textField || textField.type != TextFieldType.INPUT) continue;
				textField.text = staticData[textField.name].toString();
				textField.addEventListener(Event.CHANGE, textChangeHandler);
			}
		}
		private var infoUI:Sprite;
		private var staticData:IMapData;
		public function refreshVisible():void
		{
			infoUI.visible = !infoUI.visible;
		}
		private function textChangeHandler(event:Event):void
		{
			var textField:TextField = event.target as TextField;
			staticData.refresh(textField.name, textField.text);
		}
	}
}